<?php
namespace Admin\Controller;
use Think\Controller;

class IndexController extends BaseController {

 public function checkName($uname){
        $uname=I('get.uname');
        $res=M('users')->where(array('username'=>$uname))->find();
        $re=array();
        if(!$res){
            $re['status']=true;     
        }else{
            $re['status']=false;    
        }
        $this->ajaxReturn($re);

    }

    public function checkpwd(){
        $pwd=I('get.pwd');
        $uname=I('get.uname');
        $pwd=md5($pwd);
        $res=M('users')->where(array('username'=>$uname,'password'=>"$pwd"))->find();
        $re=array();
        if($res){
            $re['msg']='密码正确!';
            $re['status']=true;     
        }else{
            $re['msg']='密码不正确,请重新输入!';
            $re['status']=false;    
        }
        $this->ajaxReturn($re);

    }

//后台登录
 public function admin(){
        $this->display();
    }
    public function doLogin(){
        $uname=I('post.uname');
        $pwd=md5(I('post.pwd'));
        $res=M('users')->where(array('username'=>$uname,'password'=>$pwd))->find();
        if($res){
            $_SESSION['user']['id']=$res['id'];
            $_SESSION['user']['uname']=$res['username'];
	            $this->success('登录成功',U('Admin/Index/index'),2);
        }else{
            $this->error('登录失败',U('Admin/Index/admin'),2);
        }
	}
    public function logout(){
        session('user.id',null);
        session('user.uname',null);
        $this->success('注销成功',U('Admin/Index/admin'),2);
    }

//后台主页
    public function index(){
	    if(empty($_SESSION['user']['id'])){
	    	$this->error('未登录,非法访问',U('Admin/Index/admin'),0);
	    }
       $this->display();
    }

//后台退出




}